<?php

App::import('Controller', 'Events');
App::import('Controller', 'futuretweets');
App::import('Model', 'Event');
App::import('Model', 'User');
App::import('Model', 'FutureTweet');
App::import('Component', 'Session');
App::import('Component', 'Auth');



class EventsControllerTest extends ControllerTestCase {

		var $components = array('Auth', 'Cookie', 'Session', 'RequestHandler');

		function startTest()
		{
		$this->Events = new EventsControllerTest();
        $this->Events->constructClasses();
        $this->Events->initialize($this->Events);
        $this->EventsController = $this->generate('Events', array(
            'components' => array('Session', 'Auth' => array('User'), 'RequestHandler') //We mock the Auth Component here
                ));
        $this->Event = ClassRegistry::init('Event');
		}


	    public function testdeleteevent() 
		{
		$this->EventsController->Auth->staticExpects($this->any())
			 ->method('User')->with($this->logicalOr(
		 $this->equalTo('userID'), $this->equalTo('accID'), $this->equalTo('admin')))
			 ->will($this->returnCallback(array($this, 'deleteeventCallback')));
		$futuretweets = new futuretweetscontroller();
		$this->loadModel('Event');
		$this->testAction('/events/deleteevent/600');
        $event = $this->Event->find('all', array('conditions' => array('id' => 600 , 'deleted' => 0 )));
        $eventtweets = $futuretweets->eventstweetstest(600);
        $this->assertEquals(array(), $event);
        $this->assertEquals(array(), $eventtweets);
 	   }


 	   public function testdeleteeventtweet() 
		{
		$this->EventsController->Auth->staticExpects($this->any())
			 ->method('User')->with($this->logicalOr(
		 $this->equalTo('userID'), $this->equalTo('accID'), $this->equalTo('admin')))
			 ->will($this->returnCallback(array($this, 'deleteeventCallback')));

		$this->loadModel('Event');
		$futuretweets = new futuretweetscontroller();
		$this->testAction('/events/deleteeventtweet/1000/700/test1');
		$this->testAction('/events/deleteeventtweet/1001/700/test2');		
		$this->testAction('/events/deleteeventtweet/1002/700/test3');		
		$eventtweets = $futuretweets->eventstweetstest(700);
        $this->assertEquals(array(), $eventtweets);
 	   }

 	   public function testrepeattweet() 
		{
					$this->EventsController->Auth->staticExpects($this->any())
			 ->method('User')->with($this->logicalOr(
		 $this->equalTo('userID'), $this->equalTo('accID'), $this->equalTo('admin')))
			 ->will($this->returnCallback(array($this, 'deleteeventCallback')));


		$this->loadModel('Event');
		$futuretweets = new futuretweetscontroller();
		$sub_time = date('Y-m-d H:i:s');
		$date = '2012-10-25 6:30:00';
		$tweet = array('userID' => 1,'tweetText' => 'testing',
				  'eventID' => 1000,
               	  'approved' => true,
                  'release_date' => $date ,'sub_time' => $sub_time,
                  'accID' => 1 , 'reply_to' => 'mina');
		$this->EventsController->repeattweet($tweet,3,3);

		$eventtweets = $futuretweets->eventstweetstest(1000);
		$this->testAction('/events/deleteevent/1000/testing');
        $this->assertEquals(3, sizeof($eventtweets));
 	   }


 	       public function deleteeventCallback($foo) {
        if ($foo == 'accID')
            return 1;
        else {
            if ($foo == 'userID') {
                return 1;
            }
        }
        return 0;
    }

        function endTest() {
        unset($this->Events);
        ClassRegistry::flush();
    }



}
